package com.example.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.beans.PaperInformation;
import com.example.beans.WorkInfoemation;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

/**
 * Created by Administrator on 2016/4/7.
 */
public class ListViewAdapter1 extends BaseAdapter {
    public List<WorkInfoemation> list = new ArrayList<>();
    private LayoutInflater layoutInflater;
    public Context context;

    public ListViewAdapter1(Context context, List<WorkInfoemation> list) {
        this.list = list;
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }
    public void changeList(List<WorkInfoemation> list){
        this.list = list;
        notifyDataSetChanged();

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AdaperHolder adaperHolder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.list_view_layout, null);
            adaperHolder = new AdaperHolder();
            adaperHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            adaperHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(adaperHolder);

        }else{
            adaperHolder = (AdaperHolder) convertView.getTag();
        }
        adaperHolder.tv_time.setText(list.get(position).getDate());
        adaperHolder.tv_title.setText(list.get(position).getWorkname());
        return convertView;
    }

    private class AdaperHolder {
        private TextView tv_title;
        private TextView tv_time;
    }
}
